<template>
  <el-dialog
    title="题目预览"
    :visible="showDialog"
    @close="closeDialog"
    @open="open">
      <el-row>
        <el-col :span="6">【题型】：{{request.questionType|tx}}</el-col>
        <el-col :span="6">【编号】：{{request.id}}</el-col>
        <el-col :span="6">【难度】：{{request.difficulty|nd}}</el-col>
        <el-col :span="6">【标签】：{{request.tags}}</el-col>
        <el-col :span="6">【学科】：{{request.subjectName}}</el-col>
        <el-col :span="6">【目录】：{{request.directoryName}}</el-col>
        <el-col :span="6">【方向】：{{request.direction}}</el-col>
      </el-row>
       <hr>
      【题干】：<div v-html="request.question" style="color:blue"></div>
      <div v-if="request.questionType!=='3'">
        <div style="padding-bottom:5px">{{request.questionType|tx}} 选项：（以下选中的选项为正确答案）</div>
        <div v-for="item in request.options" :key="item.code" style="padding:8px 0">
          <el-radio v-if="request.questionType==='1'" :value="item.isRight" :label="1">{{item.title}}</el-radio>
          <el-checkbox v-if="request.questionType==='2'" :value="item.isRight?true:false" >{{item.title}}</el-checkbox>
        </div>
      </div>
      <hr>
      【参考答案】：<el-button type="danger" size="small" @click="preivewVideo()">视频答案预览</el-button>
      <div class="video" v-show="play">
        <video ref="video" :src="request.videoURL" controls></video>
      </div>
      <hr>
      【答案解析】：<div style="display:inline-block" v-html="request.answer"></div>
      <hr>
      【题目备注】：{{request.remarks}}
    <!-- footer插槽 -->
    <template #footer>
      <el-button type="primary" @click="closeDialog">关闭</el-button>
    </template>
  </el-dialog>
</template>

<script>
// 导入替换文本
import { difficulty, questionType } from '@/api/hmmm/constants'
// 按需导入请求
import { detail } from '@/api/hmmm/questions'
export default {
  props: {
    showDialog: {
      type: Boolean,
      default: false
    },
    // 获取到父组件传来的对象---为了获取id
    myData: {
      type: Object,
      default: () => {}
    }
  },
  filters: {
    nd (value) {
      if (value) return difficulty.find(item => item.value === +value).label
    },
    tx (value) {
      if (value) return questionType.find(item => item.value === +value).label + '题'
    }
  },
  data () {
    return {
      request: {},
      play: false
    }
  },
  methods: {
    // 关闭弹窗---子传父 ---放权
    closeDialog () {
      // console.log(111)
      this.$emit('update:showDialog', false)
      this.play = false
    },
    // 定义一个打开函数用于发送请求
    async open () {
      const { data } = await detail({ id: this.myData.id })
      console.log('基础题库详情', data)
      this.request = data
      console.log('转换啦', this.request)
    },
    preivewVideo () {
      this.play = true
      this.$refs.video.play()
    }
  }
}
</script>
<style scoped lang="scss">
.questions-preview{
  .el-col{
    padding: 10px 0;
  }
}
.video{
  width: 400px;
  height: 300px;
  video {
    width: 100%;
    height: 100%;
  }
}
</style>
